<template>
	<view class="animal_collect">
		<view class="animal_header">
			<view class="animal_header_title">
				<view class="th2">Collection
				</view>
				<view class="th1">Friend</view>
			</view>
			<image aspectFit class="index_header_img" src="/static/col-bg.png" mode=""></image>
		</view>
		<view class="animal_main">
			<view class="collect_item" v-for="item in colList">
				<view class="item_left">
					<image @click="jumpGo(item.did)" :src="item.pet_coverURL" mode="aspectFill"></image>
				</view>
				<view class="item-center">
					<view class="tdesc_tit">
						{{item.pet_name}}
					</view>
					<view class="tdesc_bot">
						{{item.pet_engName}}
					</view>
					<view class="tdesc_bot">
						{{item.pet_life}}
					</view>

				</view>
				<view class="item-right">
					<view class="changeCol active" @click="delCol(item.did,item.uid)">
						<image src="/static/collect.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view-tabbar :idx="'2'"></view-tabbar>
	</view>
</template>

<script>
	import Tabbar from '@/components/tabbar.vue'
	import {
		userColList,
		addCol
	} from "@/api/index.js"
	export default {
		data() {
			return {
				colList: []
			};
		},
		components: {
			'view-tabbar': Tabbar
		},
		methods: {
			jumpGo(id) {
				uni.setStorageSync("id", id)
				uni.navigateTo({
					url: `/pages/detail/detail`
				})

				console.log(id)
			},
			delCol(did, uid) {
				console.log(did, uid)
				addCol(uid, did).then((content) => {
					console.log(content.data)
					this.getList()
				})
			},
			async getList() {

				await userColList(uni.getStorageSync("uid")).then((content) => {
					let {
						data: {
							code,
							data
						}
					} = content
					console.log(code, data)
					if (code == 200) {
						this.colList = data
					}
				})
			}
		},
		onShow() {
			if (uni.getStorageSync("uid")) {
				uni.hideTabBar({
					animation: false
				})
				this.getList()
			} else {
				uni.showModal({
					content: '请先登录',
					confirmText: "确认", // 确认按钮的文字
					showCancel: false, // 是否显示取消按钮，默认为 true
					confirmColor: '#f55850',
					success: (res) => {
						if (res.confirm) {
							uni.navigateTo({
								url: "/pages/login/login"
							})
						} else {
							console.log('cancel') //点击取消之后执行的代码
						}
					}
				})
			}

		},
	}
</script>

<style lang="scss">
	.animal_collect {
		height: 100vh;
		background-color: #a1b275;
	}

	.animal_search {
		margin: 0 15px;
		height: 50px;
		background-color: white;
		border-radius: 16px;
		display: flex;
		align-items: center;
		background-color: #ffffff;

		.search_icon {
			width: 20px;
			height: 20px;
			margin: 10px;
		}

		.sPlo {
			font-size: 14px;
			color: #BBC3CE;
			font-weight: 500;
		}

	}

	.animal_header {
		width: 100%;
		height: 150px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.index_header_img {
		display: block;
		width: 172px;
		height: 100px;
		margin-right: 20px;
		margin-top: 10px;
	}

	.animal_header_title {
		margin-top: 20px;
		margin-left: 40px;
		color: white;
		line-height: 36px;

		.th2 {
			font-size: 28px;
			font-weight: 100;
		}

		.th1 {
			font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
			font-size: 28px
		}
	}

	.animal_main {
		border-radius: 43px 43px 0 0;
		background-color: #f3f2f2;
		min-height: 500px;
		display: flex;
		flex-direction: column;
		align-items: center;



		.collect_item {
			width: 333px;
			height: 96px;
			border-radius: 17px;
			background-color: white;
			margin-bottom: 20px;
			display: flex;
			align-items: center;


			&:first-child {
				margin-top: 30px;
			}

			.item_left {
				margin-left: 4px;
				width: 88px;
				height: 88px;
				background-color: lightblue;
				border-radius: 17px;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.item-center {
				height: 70px;
				width: 150px;
				margin-left: 20px;

				.tdesc_tit {
					font-size: 18px;
					color: #333;
				}

				.tdesc_bot {
					margin-top: 6px;
					font-size: 14px;
					color: gray;
					line-height: 14px;

					&:last-child {
						margin-top: 2px;
					}
				}
			}

			.item-right {
				height: 88px;
				width: 30px;
				margin-left: 20px;
				display: flex;
				align-items: flex-end;
				justify-content: flex-end;
				margin-bottom: 20px;

				.changeCol {
					width: 22px;
					height: 22px;
					background-color: #ECEBEB;
					border-radius: 50%;
					display: flex;
					justify-content: center;
					align-items: center;
					transition: .3s;

					&.active {
						background-color: #ffd967;
						box-shadow: 0 2px 6px #ffd967;
					}

					image {
						width: 11px;
						height: 11px;
					}
				}
			}
		}
	}
</style>